package jsyf.oa.dao.wechat.service_otherCompany;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import jsyf.oa.entity.wechat.service_company.TokenEntity;
import jsyf.oa.idao.BaseDao;
import jsyf.oa.ientity.IBaseEntity;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class CompanyTokenDao extends BaseDao {

    public CompanyTokenDao() {
        super.iBaseEntity = new TokenEntity();
    }

    @Override
    public  IBaseEntity convertJson2Entity(JSONObject json) {
        return JSON.toJavaObject(json, TokenEntity.class);
    }

    public String saveAccessToken(TokenEntity tokenEntity, int type) {
        super.add(tokenEntity);
        return tokenEntity.getId();
    }

    public List<JSONObject> getAccessTokenByType(String jsonData,int type) {
        return super.getJSONListByCondition("AND COMPANY_ID=? AND type = ? ORDER BY CREATE_TIME DESC", new Object[]{jsonData,type});
    }

}

